define
(
    ["require",
     "lib/knockout",
     "../Types"],
    function (require, ko, Types)
    {
        ko.bindingHandlers.switchBind = 
        {
            init: function(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext)
            {
                var bindingTerm = valueAccessor();
                var valueUnwrapped = ko.utils.unwrapObservable(bindingTerm());
                $(element).bootstrapSwitch('setState', valueUnwrapped);
            },

            update: function(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext)
            {
                $(element).on('switch-change', function (e, data) 
                {
                    value = data.value;
                    var bindingTerm = valueAccessor();
                    bindingTerm(value);
                });
            }
        };
    }
);